package com.nacos.service;

import com.nacos.mapper.TestMapper;
import com.nacos.util.Result;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;

@Service
public class TestService {
    @Autowired
    private TestMapper testMapper;
    public String test01() {
        int count =testMapper.add();
        if (count==1){
            return "添加成功";
        }else {
            return "添加失败";
        }
    }

    @SneakyThrows
    public Result importDeviceInfoExcel(MultipartFile file, Integer categoryId, HttpServletRequest request) {
        InputStream inputStream = file.getInputStream();

        FileOutputStream fileOutputStream = new FileOutputStream(new File("E:\\img\\测试Excel.xlsx"));

        int i;//从输入流读取一定数量的字节，返回 0 到 255 范围内的 int 型字节值
        while ((i = inputStream.read()) != -1) {
            fileOutputStream.write(i);
        }

        System.out.println(file);
        System.out.println(categoryId);
        return Result.OK();
    }
}
